
=httpResponse: Address Space=

The 
[[doc:tpt:http:HTTPBridge|HTTPBridge]] 
inserts a dynamic space into the request scope it uses when issuing
its sub-request into the overlay's wrapped space.
This space resolves requests for identifiers using
the <code>httpResponse:</code> URI scheme.
The <code>httpResponse:</code> 
address space provides interfaces for information that can be included in
the transport's external response to the detected HTTP request.
The address space can accept multiple requests with the SINK
verb and will serialize all of the accumulated state when
the external response is returned to the client.


===httpResponse:/cookie===

A request with the SINK verb sets an
[http://en.wikipedia.org/wiki/HTTP_cookie|HTTP Cookie] 
for the HTTP transport to include in its external
response.

The cookie '''must''' be an instance of
{javadoc}javax.servlet.http.Cookie{/javadoc} 
and '''must''' be set as the primary argument
of the request.

For example, the following sets a cookies
for the external response:

{java}public void onSource(INKFRequestContext context)
  {
  ...
  response = context.createResponseFrom(representation);
  ...
  Cookie cookie = new Cookie("rememberthis", "special-value");
  cookie.setPath("/");
  cookie.setMaxAge(60000);
  context.sink("httpResponse:/cookie", cookie);
  }
{/java}


===httpResponse:/header/XXXXX===

A request with the SINK verb sets an
HTTP header value for the HTTP transport
to include in its external response.
The form of the identifier is:

{literal}httpResponse:/header/{header-name}{/literal}


The header value '''must''' be an instance
of {javadocclass}java.lang.String{/javadocclass}
and '''must''' be set as the primary argument of the
request.

For example, the following code sets the header
"FROM" to "webmaster@myco.com"

{java}public void onSource(INKFRequestContext context)
  {
  ...
  context.createResponseFrom(representation);
  ...
  context.sink("httpResponse:/header/FROM", "webmaster@myco.com");
  }
{/java}

===httpResponse:/code===


A request with the SINK verb sets the HTTP response code
for the HTTP external response sent by the transport.

For example, to set the response code to "204":

{java}public void onSource(INKFRequestContext context)
  {
  ...
  context.createResponseFrom(representation);
  ...
  context.sink("httpResponse:/code", 204);
  }
{/java}



===httpResponse:/redirect===

A request with the SINK verb sets the HTTP code to "302" (redirect)
and includes the new resource identifier.

For example, the following code will cause a redirect to be 
returned by the transport that will redirect the user
to the 1060 Research web site:

{java}public void onSource(INKFRequestContext context)
  {
  context.sink("httpResponse:/redirect", "http://www.1060research.com");
  }
{/java}


==Advanced - Response Metadata==

An alternate mechanism for writing to the response space is to attach metadata to a response that will return to the
bridge. i.e.

{java}response.setMetaData("httpResponse:/code",404);
{/java}
is equivalent
{java}context.sink("httpResponse:/code",404);
{/java}




